/**
 * Created on 2020-6-23
 * Last editor on 2020-6-28
 * @author: guixin
 */
package com.example.auv_660.order;

import org.json.JSONException;
import org.json.JSONObject;

public class OrderJson {
    public static final String AUVID = "AUVID";                     // AUVID键值
    public static final String SOURCE = "Source";                   // 命令来源键值
    public static final String ORDER = "Order";                     // 命令类型键值
    public static final String CONTENT = "Content";                 // 命令内容键值

    public static final String HEARTBEAT_ORDER = "HeartBeat";       // 心跳命令
    public static final String INFORMATION_ORDER = "Information";   // 查询信息命令
    public static final String SELFCHECKING_ORDER = "SelfChecking"; // 自检命令
    public static final String BRAKING_ORDER = "Breaking";          // 制动命令
    public static final String REMOTECONTROL_ORDER = "RemoteControl";   // 遥控命令
    public static final String DIRECTROUTE_ORDER = "DirectRoute";   // 直航命令
    public static final String NAVIGATION_ORDER = "Navigation";     // 导航命令
    public static final String COURSEREVERSAL_ORDER = "CourseReversal"; // 返航命令

    public static final String DEVICE = "Device";                   // 命令来自设备端

    /**
     * 生成json格式的命令
     * @param ID
     * @param Order
     * @param Content
     * @return
     * @throws JSONException
     */
    public static String CreateOrderJson(String ID, String Order, String Content) throws JSONException
    {
        JSONObject OrderJson = new JSONObject();
        OrderJson.put(SOURCE, DEVICE);
        OrderJson.put(AUVID, ID);
        OrderJson.put(ORDER, Order);
        OrderJson.put(CONTENT, Content);
        return OrderJson.toString();
    }

    /**
     * 生成json格式的信息
     * @param information
     * @return
     * @throws JSONException
     */
    public static JSONObject CreateInformationJson(Information information) throws JSONException
    {
        JSONObject LocationJson = new JSONObject();
        LocationJson.put("Longitude", information.getLocationValue()[0]);
        LocationJson.put("Latitude", information.getLocationValue()[1]);

        JSONObject OrientationJson = new JSONObject();
        OrientationJson.put("Azimuth", information.getOrientationValue()[0]);
        OrientationJson.put("Pitch", information.getOrientationValue()[1]);
        OrientationJson.put("Roll", information.getOrientationValue()[2]);

        JSONObject SpeedJson = new JSONObject();
        SpeedJson.put("XSpeed", information.getSpeedValue()[0]);
        SpeedJson.put("YSpeed", information.getSpeedValue()[1]);
        SpeedJson.put("ZSpeed", information.getSpeedValue()[2]);

        JSONObject InformationJson = new JSONObject();
        InformationJson.put("Location", LocationJson);
        InformationJson.put("PhoneBattery", information.getPhoneBatteryValue());
        InformationJson.put("Orientation", OrientationJson);
        InformationJson.put("Speed", SpeedJson);

        return InformationJson;
    }
}
